/*
 * This file is part of the <a href="http://code.google.com/p/pux">PUX Framework</a>
 *
 * Copyright 2008 by <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package de.teamskill.pux.engine;

/**
 * ConstantInputPort
 * 
 * @author <a href="mailto:jfendler@polytechnic.edu.na">Jens Fendler</a>
 * 
 */
public class ConstantInputPort extends InputPort {

	/**
	 * ConstantInputPort Constructor
	 * 
	 * @param data
	 */
	public ConstantInputPort(Object data) {
		super();
		setData(data);
	}

	/**
	 * ConstantInputPort Constructor
	 * 
	 * @param name
	 * @param data
	 */
	public ConstantInputPort(String name, Object data) {
		super(name);
		setData(data);
	}

	/**
	 * ConstantInputPort Constructor
	 * 
	 * @param name
	 * @param node
	 * @param data
	 */
	public ConstantInputPort(String name, AbstractNode node, Object data) {
		super(name, node);
		setData(data);
	}

	/**
	 * ConstantInputPort Constructor
	 * 
	 * @param name
	 * @param node
	 * @param required
	 * @param data
	 */
	public ConstantInputPort(String name, AbstractNode node, boolean required, Object data) {
		super(name, node, required);
		setData(data);
	}

	/**
	 * ConstantInputPort Constructor
	 * 
	 * @param name
	 * @param node
	 * @param required
	 * @param type
	 * @param data
	 */
	public ConstantInputPort(String name, AbstractNode node, boolean required, Class<?> type, Object data) {
		super(name, node, required, type);
		setData(data);
	}

	/**
	 * @see de.teamskill.pux.engine.InputPort#fetchBuffer()
	 */
	public final DataElement fetchBuffer() {
		return fetchBuffer(false);
	}

	/**
	 * @see de.teamskill.pux.engine.InputPort#fetchBuffer(boolean)
	 */
	public final DataElement fetchBuffer(boolean clearBuffer) {
		DataElement de = super.fetchBuffer(false);
		if (de != null) {
			return de;
		} else {
			throw new IllegalStateException(getNode().getNodeName() + ": Constant port " + getName()
					+ " contains null DataElement.");
		}
	}

}
